package deployr.cli;

import static java.util.Collections.*;

import java.util.*;

public class ResponderChain extends Responder {

	private final Iterable<Responder> responders;

	public ResponderChain(Collection<Responder> responders) {
		this.responders = unmodifiableCollection(responders);
	}

	public Result respondTo(String method, String requestURI, Input input) {
		for (Responder responder : responders) {
			if (responder.shouldRespond(method, requestURI)) {
				return responder.respondTo(method, requestURI, input);
			}
		}
		return new Result(404);
	}

}
